/*
    XTU OJ: 1353
    by: fifth_light
*/

#include <stdio.h>
#include <stdint.h>

int max_digit = -1;
int string[32];
int string_length;
int num;

#define CONVERT_CHAR(char) (((char) >= '0' && (char) <= '9') ? \
    ((char) - '0') : ((char) - 'A' + 10))

int convert(int base) {
    int64_t res = 0;
    for (int i = 0; i < string_length; i++) {
        res *= base;
        res += string[i];
        // 2 ^ 31 - 1, num不会有那么大
        if (res > 2147483647) {
            return -1;
        }
    }
    return res;
}

int main(void) {
    while(1) {
        int c;
        // 读取字符串
        string_length = 0;
        max_digit = -1;
        while ((c = getchar()), (c != ' ' && c != EOF && c != '\n')) {
            int digit = CONVERT_CHAR(c);
            string[string_length++] = digit;
            if (digit > max_digit) {
                max_digit = digit;
            }
        }
        if (c == EOF) {
            break;
        }
        if (c == '\n') {
            continue;
        }
        // 读取数字
        scanf("%d", &num);
        // printf("max: %d\n", max_digit);
        int found = 0;
        for (int i = max_digit; i < 16; i++) {
            if (convert(i + 1) == num) {
                printf("%d\n", i + 1);
                found = 1;
                break;
            }
        }
        if (!found) {
            puts("Impossible");
        }
    }
    return 0;
}
